load("//bzl:cpp_library.bzl", "cpp_library")

package(default_visibility = ["//visibility:public"])

cpp_library(
    name = "arena",
    hdrs = [
        "Arena.h",
    ],
    textual_hdrs = [
        "Arena-inl.h",
    ],
    deps = [
        ":malloc",
        "//folly:conv",
        "//folly:likely",
        "//folly:memory",
        "//folly/lang:align",
        "//folly/lang:checked_math",
        "//folly/lang:exception",
        "//folly/lang:safe_assert",
        "@boost.intrusive",
    ],
)

cpp_library(
    name = "mallctl_helper",
    srcs = ["MallctlHelper.cpp"],
    hdrs = ["MallctlHelper.h"],
    deps = [
        ":malloc",
        "//folly:format",
        "//folly:string",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "malloc",
    hdrs = ["Malloc.h"],
    deps = [
        "//folly:portability",
        "//folly/lang:bits",
        "//folly/lang:exception",
        "//folly/memory/detail:malloc_impl",
        "//folly/portability:malloc",
    ],
)

cpp_library(
    name = "memory_resource",
    hdrs = ["MemoryResource.h"],
)

cpp_library(
    name = "not_null",
    srcs = [],
    hdrs = [
        "not_null.h",
    ],
    textual_hdrs = [
        "not_null-inl.h",
    ],
    deps = [
        "//folly:memory",
        "//folly:portability",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "reentrant_allocator",
    srcs = ["ReentrantAllocator.cpp"],
    hdrs = ["ReentrantAllocator.h"],
    deps = [
        "//folly:portability",
        "//folly/lang:bits",
        "//folly/lang:safe_assert",
        "//folly/portability:sys_mman",
    ],
)

cpp_library(
    name = "sanitize_address",
    srcs = ["SanitizeAddress.cpp"],
    hdrs = ["SanitizeAddress.h"],
    deps = [
        "//folly:portability",
        "//folly/lang:extern",
    ],
)

cpp_library(
    name = "sanitize_leak",
    srcs = ["SanitizeLeak.cpp"],
    hdrs = ["SanitizeLeak.h"],
    deps = [
        "//folly:portability",
        "//folly/lang:extern",
    ],
)

cpp_library(
    name = "thread_cached_arena",
    srcs = ["ThreadCachedArena.cpp"],
    hdrs = ["ThreadCachedArena.h"],
    deps = [
        "//folly:likely",
        "//folly:synchronized",
        "//folly:thread_local",
        "//folly/memory:arena",
    ],
)

cpp_library(
    name = "uninitialized_memory_hacks",
    hdrs = ["UninitializedMemoryHacks.h"],
)

cpp_library(
    name = "jemalloc_nodump_allocator",
    srcs = ["JemallocNodumpAllocator.cpp"],
    hdrs = ["JemallocNodumpAllocator.h"],
    deps = [
        "//folly:c_portability",
        "//folly:conv",
        "//folly:string",
        "//folly/memory:malloc",
        "//folly/portability:config",
        "//folly/portability:malloc",
        "//folly/portability:sys_mman",
        "@glog",
    ],
)

cpp_library(
    name = "jemalloc_huge_page_allocator",
    srcs = ["JemallocHugePageAllocator.cpp"],
    hdrs = ["JemallocHugePageAllocator.h"],
    deps = [
        "//folly:c_portability",
        "//folly/memory:malloc",
        "//folly/portability:malloc",
        "//folly/portability:string",
        "//folly/portability:sys_mman",
        "//folly/portability:sys_types",
        "@glog",
    ],
)

# Disable tests for now.
#cpp_unittest(
#    name = "jemalloc_huge_page_allocator_test",
#    srcs = ["JemallocHugePageAllocatorTest.cpp"],
#    hdrs = [],
#    allocator = "jemalloc",
#    labels = ["oss-broken"],
#    deps = [
#        "//folly/container:f14_hash",
#        "//folly/memory:jemalloc_huge_page_allocator",
#        "//folly/memory:malloc",
#        "//folly/portability:gtest",
#    ],
#)
#
#cpp_unittest(
#    name = "jemalloc_nodump_allocator_test",
#    srcs = ["JemallocNodumpAllocatorTest.cpp"],
#    hdrs = [],
#    allocator = "jemalloc",
#    deps = [
#        "//folly/io:iobuf",
#        "//folly/memory:jemalloc_nodump_allocator",
#        "//folly/memory:malloc",
#        "//folly/portability:gtest",
#    ],
#)
